<?php
namespace app\MAPP\admin\mode\login;

use function core\alert;
use function core\p;

class func{

    var $conf;
    var $db;
    function __construct()
    {
        $this->msg = \core\lib\Queryinfom::Newinstance();
        $this->db = \Extentions\mysql\Db::instance();
        $this->conf = \core\lib\Config::all("SQLlib\\book\\sql");
    }

    function reg($uname,$passwd,$phone = 0){
        $temp = $this->db->pre_exec($this->conf["add"],array($uname,$passwd,$phone));
        return $temp;
    }

    function login($uname,$passwd){
        $temp = $this->db->pre_exec($this->conf["login"],array($uname,$passwd));
        if (count($temp) == 1){
            return true;
        }else{
            return false;
        }
    }

    function usercheck($uname){
        $temp = $this->db->pre_exec($this->conf["check_user"],array($uname));
        return $temp;
    }

    function cookiechek(){

    }

    function booklist(){
        $temp = $this->db->fetchall($this->conf["lists"]);
        return $temp;
    }

    function addnews($au = "",$ti = "",$cont = ""){
        $id = $this->db->pre_exec($this->conf["maxid"],[]);
        $id = $id[0][0]+1;
        $temp = $this->db->pre_exec($this->conf["addnews"],[$id,$au,$ti,$cont]);
        return $temp;
    }

    function delnews($id){
        if ($id == ""){
            throw new \ErrorException("null err");
            return;
        }
        $temp = $this->db->pre_exec($this->conf["delnews"],[$id]);
        return $temp;
    }

    function delmany($ids = []){
        if ($ids == null) return;
        foreach ($ids as $d){
            if ($d == null) return;
            $this->db->pre_exec($this->conf["delnews"],[$d]);
        }
    }

}